package com._51cto.healthy.controller;

import com._51cto.healthy.content.P;
import com._51cto.healthy.content.R;
import com._51cto.healthy.pojo.Food;
import com._51cto.healthy.service.FoodService;
import io.swagger.models.auth.In;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/food")
public class FoodController {
    @DubboReference
    private FoodService foodService;
    @GetMapping("/page/{pageSize}/{pageNum}")
    public R findAll(@RequestParam(value = "query",required = false)String query,
                     @PathVariable("pageSize")Integer pageSize,
                     @PathVariable("pageNum")Integer pageNum){
        P<Food> all = foodService.findAll(query, pageSize, pageNum);
        return R.success(all);

    }
    @DeleteMapping("/{id}")
    public R delete(@PathVariable("id")Integer id){
        foodService.deleteByPK(id);
        return R.success("删除成功!!!");
    }

    @PostMapping
    public R insert(@RequestBody Food food){
        foodService.insert(food);
        return R.success("添加成功");
    }
    @PutMapping
    public R update(@RequestBody Food food){
        foodService.update(food);
        return R.success("修改成功");
    }
}
